<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/common.css"/>
</head>
<body class="ad_add">
<article class="bigBox">
    <section class="container">
        <label class="flex_a h100 bdb plr24 bw">
            <span>员工名称</span>
            <input type="text" placeholder="请输入" class="tae ml20 flex1" name="name">
        </label>
        <label class="flex_a h100 bdb plr24 bw">
            <span>手机号</span>
            <input type="number" placeholder="请输入" class="tae ml20 flex1" name="phone">
        </label>
        <label class="flex_a h100 bdb plr24 bw">
            <span>密码</span>
            <input type="password" placeholder="请输入" class="tae ml20 flex1" name="pass">
        </label>
        <label class="flex_a h100 bdb plr24 bw">
            <span>重复密码</span>
            <input type="text" placeholder="请输入" class="tae ml20 flex1" name="passa">
        </label>
        <div class="flex_sb h100 plr24 bw bdb">
            <span>账号状态</span>
            <div class="flex_a">
                <label class="flex_a">
                    <input type="radio" name="type2" hidden class="anchor status1" value="1">
                    <span class="anchor_ico"></span>
                    <cite class="ml10">启用</cite>
                </label>
                <label class="flex_a ml40">
                    <input type="radio" name="type2" hidden class="anchor status2" value="2">
                    <span class="anchor_ico"></span>
                    <cite class="ml10">禁用</cite>
                </label>
            </div>
        </div>
    </section>
    <footer class="ptb20 pw100">
        <div class="plr30">
            <button class="border-r6 bgc1 colw tac lh90 pw100 btn_tap font16">保存</button>
        </div>
    </footer>
</article>
</body>
</html>
<script src="../js/jquery.min.js"></script>
<script src="../js/dlc.js"></script>
<script>
    <!--详情-->
    dlctipbox.loading();
    dlc_request('/api/employee/findEmployee',{'agentId':getUrlParam('id')},function(res){
        console.log(res);
        dlctipbox.clear();
        $('input[name=name]').val(res.data.name);
        $('input[name=phone]').val(res.data.phone);
        $('.status'+res.data.status).attr('checked','checked');
    });

    //修改
    $('.btn_tap').click(function(){
        var status = $('input[name=type2]:checked').val();
        var phone = $('input[name=phone]').val();
        var name = $('input[name=name]').val();
        var pass = $('input[name=pass]').val();
        var passa = $('input[name=passa]').val();
       if(isNull(name)){
            dlctipbox.show('请输入名称');
        }else if(isNull(phone)){
            dlctipbox.show('请输入手机号码');
        }else if(!checkMobileAndTel(phone)){
            dlctipbox.show('手机号码格式不正确')
        }
        else if(pass!=passa){
            dlctipbox.show('两次输入的密码不一致');
        }
        else if(isNull(pass)){
            dlctipbox.show('请输入密码');
        }else if(isNull(passa)) {
            dlctipbox.show('请再次输入密码');
        }else if(isNull(status)){
            dlctipbox.show('请选择账号状态');
        }else{
            var data = {
                'agentId':getUrlParam('id'),
                'name':name,
                'status':status,
                'phone':phone,
                'password':pass,
                'rePassword':passa
            };
            console.log(data);
            dlc_request('/api/employee/updateEmployee',data,function(res){
                console.log(res);
                if(res.code == 1){
                    dlctipbox.show('修改成功');
                    setTimeout(function(){
                        history.go(-1);
                    },2000);
                }else{
                    dlctipbox.show(res.msg);
                }
            });
        }
    });
</script>